package com.erp.myAdapter

import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.erp.R
import com.erp.bean.OemBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_duizhang_item.view.*
import kotlinx.android.synthetic.main.lv_oem_item.view.*

class OemAdapter (var DuizhangList: MutableList<OemBean>, var context: Context): BaseAdapter() {
    var minflater: LayoutInflater = LayoutInflater.from(context)
    @SuppressLint("InflateParams")
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        var vh : ViewHolder
        Log.d("onSuccess", "position=$position")
        if(convertView==null){
            v = minflater.inflate(R.layout.lv_oem_item,null)
            vh = ViewHolder(v)
            v.tag = vh
        }else{
            v = convertView
            vh = convertView.tag as ViewHolder
        }
        val bean=DuizhangList[position]
        Myutil.settv(bean.o_onum,vh.TvOnum)
        Myutil.settv(bean.shop_name,vh.TvShopName)
        Myutil.settv(Myutil.getdata(bean.ctime),vh.TvCtime)
        Myutil.settv(Myutil.getdata(bean.acceptance_time),vh.TvAcceptanceTime)
        Myutil.settv(Myutil.getdata(bean.o_plan_warehousing_time),vh.TvPlanWarehousingTime)
        Myutil.settv(Myutil.getdata(bean.deliver_time_0),vh.TvDeliverTime)
        return v
    }

    override fun getItem(position: Int): Any = DuizhangList[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int = DuizhangList.size

    class ViewHolder(v: View) {
        var TvOnum: TextView = v.TvOnum
        var TvShopName: TextView = v.TvShopName
        var TvCtime: TextView = v.TvCtime
        var TvAcceptanceTime: TextView = v.TvAcceptanceTime
        var TvPlanWarehousingTime: TextView = v.TvPlanWarehousingTime
        var TvDeliverTime: TextView = v.TvDeliverTime
    }
}